/*=========================================================================
Elite College as Engines of Upward Mobility: Evidence from Colombia's Ser Pilo Paga
Authors: Juliana Londoño-Vélez, Catherine Rodriguez, Fabio Sánchez
and Luis Esteban Álvarez-Arango

Creation date: June 6th, 2025
--------------------------------------------------------------------------
Figures 2a, 2b, 3a and 3b
=========================================================================*/
********************************************************************************

use "${data}/data_RD", clear
keep if icfes_per==20142
glo cond_saber11 "eligible_sisben==1"
glo cond_sisben	"eligible_saber11==1"
glo lim_saber11	40
glo lim_sisben 20

cap drop mean_include*
cap drop cut_saber_11 
cap drop cut_sisben
gegen cut_saber11=cut(running_saber11), at(-100(2)100)
gegen mean_include_saber11 = tag(cut_saber11) if eligible_sisben==1
gegen cut_sisben=cut(running_sisben), at(-40(1)40)
gegen mean_include_sisben = tag(cut_sisben) if eligible_saber11==1

rdrobust access_0 running_saber11 if ${cond_saber11}, masspoints(off) 
local bw=e(h_l)
cap drop kw
gen kw = ( (( (`bw') - abs(running_saber11) ) /(`bw')) * (abs(running_saber11) < (`bw')) )
cap drop bin
gegen bin =  mean(access_0) if ${cond_saber11}, by(cut_saber11)
twoway 	(lfit access_0 running_saber11 [pw=kw] if abs(running_saber11)<`bw' & ${cond_saber11} & running_saber11 < 0, sort lcolor(black) ) (lfit access_0 running_saber11 [pw=kw] if abs(running_saber11)<`bw' & ${cond_saber11} & running_saber11 >= 0, sort lcolor(black) ) (scatter bin cut_saber11 if mean_include_saber11==1 & abs(running_saber11)<${lim_saber11}, mc(black) ms(O) msize(small)), xline(0, lcolor(red) lpattern(dash)) xsize(8) xlab(-40(20)40) ylab(0(0.2)1) xtitle(Distance to SABER 11 cutoff) caption(Sample restricted to low-SES students., size(small)) legend(off) graphregion(color(white)) ytitle("")
graph export "${outcomes}/Fig2A.pdf", replace 

rdrobust access_6 running_saber11 if ${cond_saber11}, masspoints(off) 
local bw=e(h_l)
cap drop kw
gen kw = ( (( (`bw') - abs(running_saber11) ) /(`bw')) * (abs(running_saber11) < (`bw')) )
cap drop bin
gegen bin =  mean(access_6) if ${cond_saber11}, by(cut_saber11)
twoway 	(lfit access_6 running_saber11 [pw=kw] if abs(running_saber11)<`bw' & ${cond_saber11} & running_saber11 < 0, sort lcolor(black) ) (lfit access_6 running_saber11 [pw=kw] if abs(running_saber11)<`bw' & ${cond_saber11} & running_saber11 >= 0, sort lcolor(black) ) (scatter bin cut_saber11 if mean_include_saber11==1 & abs(running_saber11)<${lim_saber11}, mc(black) ms(O) msize(small)), xline(0, lcolor(red) lpattern(dash)) xsize(8) xlab(-40(20)40) ylab(0(0.2)1) xtitle(Distance to SABER 11 cutoff) caption(Sample restricted to low-SES students., size(small)) legend(off) graphregion(color(white)) ytitle("")
graph export "${outcomes}/Fig2B.pdf", replace 

rdrobust access_6_hq running_saber11 if ${cond_saber11}, masspoints(off) 
local bw=e(h_l)
cap drop kw
gen kw = ( (( (`bw') - abs(running_saber11) ) /(`bw')) * (abs(running_saber11) < (`bw')) )
cap drop bin
gegen bin =  mean(access_6_hq) if ${cond_saber11}, by(cut_saber11)
twoway 	(lfit access_6_hq running_saber11 [pw=kw] if abs(running_saber11)<`bw' & ${cond_saber11} & running_saber11 < 0, sort lcolor(black) ) (lfit access_6_hq running_saber11 [pw=kw] if abs(running_saber11)<`bw' & ${cond_saber11} & running_saber11 >= 0, sort lcolor(black) ) (scatter bin cut_saber11 if mean_include_saber11==1 & abs(running_saber11)<${lim_saber11}, mc(black) ms(O) msize(small)), xline(0, lcolor(red) lpattern(dash)) xsize(8) xlab(-40(20)40) ylab(0(0.2)1) xtitle(Distance to SABER 11 cutoff) caption(Sample restricted to low-SES students., size(small)) legend(off) graphregion(color(white)) ytitle("")
graph export "${outcomes}/Fig3A.pdf", replace 

rdrobust access_6_lq running_saber11 if ${cond_saber11}, masspoints(off) 
local bw=e(h_l)
cap drop kw
gen kw = ( (( (`bw') - abs(running_saber11) ) /(`bw')) * (abs(running_saber11) < (`bw')) )
cap drop bin
gegen bin =  mean(access_6_lq) if ${cond_saber11}, by(cut_saber11)
twoway 	(lfit access_6_lq running_saber11 [pw=kw] if abs(running_saber11)<`bw' & ${cond_saber11} & running_saber11 < 0, sort lcolor(black) ) (lfit access_6_lq running_saber11 [pw=kw] if abs(running_saber11)<`bw' & ${cond_saber11} & running_saber11 >= 0, sort lcolor(black) ) (scatter bin cut_saber11 if mean_include_saber11==1 & abs(running_saber11)<${lim_saber11}, mc(black) ms(O) msize(small)), xline(0, lcolor(red) lpattern(dash)) xsize(8) xlab(-40(20)40) ylab(0(0.2)1) xtitle(Distance to SABER 11 cutoff) caption(Sample restricted to low-SES students., size(small)) legend(off) graphregion(color(white)) ytitle("")
graph export "${outcomes}/Fig3B.pdf", replace 
